package com.esiag.isidis.marshaling;

public class Tram {
	static Tram instance = null;

	private Tram() {
	}

	public static Tram getInstance() {
		if (instance == null)
			instance = new Tram();
		return instance;
	}

	byte addByte(int bit, byte x) {
		x = (byte) (x << 1);
		x = (byte) (x | bit);
		return x;
	}
	

	byte setByte(int val1, int val2) {
		byte b = (byte) val1;//3

		int n2 = Integer.toBinaryString(val2).length();//size =4
		b = (byte) (b << 4 - n2);

		String s = Integer.toBinaryString(val2);
		for (int i = 0; i < s.length(); i++) {
			System.out.println("s :" + i + " "+s.charAt(i));
			if (s.charAt(i) == '1')
			{
				b = addByte(1, b);
			}
			else
			{
				b = addByte(0, b);
			}
		}
		return b;
	}

	public byte[] setTram(int TypeSource, int idSource, int codeOrder) {
		byte b1 = setByte(TypeSource, idSource);
		System.out.println(b1);
		byte b2 = (byte) codeOrder;
		byte[] t = new byte[] { b1, b2 };
		return t;
	}
	


}
